/*
*	RPGx AMX Mod X Plugin
*	Copyright (C) 2010 by roflmao456
*
*	This program is free software: you can redistribute it and/or modify
*	it under the terms of the GNU General Public License as published by
*	the Free Software Foundation, either version 3 of the License, or
*	(at your option) any later version.
*
*	This program is distributed in the hope that it will be useful,
*	but WITHOUT ANY WARRANTY; without even the implied warranty of
*	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*	GNU General Public License for more details.
*
*	You should have received a copy of the GNU General Public License
*	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <csx>
#include <fun>
#include <hamsandwich>

/* 
* This is where you could change your saving option from:
* - None (comment both includes)
* - nVault (comment only sqlx include; default)
* - SQL (comment only nvault include)
*/

#include <nvault>
//#include <sqlx>

/*
* Increase this if you don't see some upgrades
*/
#define MAX_UPGRADES 32

#define _VAULT defined _nvault_included
#define _SQL defined _sqlx_included
#define SAVABLE _VAULT || _SQL

#define required_xp(%1) get_pcvar_num(g_pXPStart) + (g_iLevel[%1] * get_pcvar_num(g_pXPInc))
#define PlaySound(%1,%2) client_cmd(%1, "spk sound/rpgx/%s.wav", %2)

#if _VAULT
	new g_hVault;
#endif
#if _SQL
	new Handle:g_hSQLTuple;
	new g_szSQLTable[64], g_szSQLHost[64], g_szSQLUser[64], g_szSQLPass[64], g_szSQLDB[64];
	new g_pSQLHost, g_pSQLUser, g_pSQLPass, g_pSQLDB, g_pSQLTable;
#endif

new g_iUpgrades;

new g_fwPluginReady, g_fwPluginAuth, g_fwPlayerSpawn, g_fwPlayerLevelUp, g_fwPlayerDeath,
	g_fwPlayerHurt, g_fwPluginUpgradePurchase, g_fwPluginUpgradeSell, g_fwLastResult;

new g_pXPNotice, g_pXPMax, g_pXPStart, g_pXPInc, g_pXPKill, g_pXPHeadshot, g_pXPDamage, g_pXPKnifeDmg,
	g_pXPTeamWin, g_pXPBombPlant, g_pXPBombDefuse, g_pXPBombExplode;

new g_pCreditsInc, g_pCreditsStart, g_pCreditsSellPct;

new bool:g_bIsFrozen[33];

new g_iLevel[33], g_iXP[33], g_iCredits[33], g_iSpawnHealth[33];

new g_iUpgrade_Level[33][MAX_UPGRADES], g_iUpgrade_Info[MAX_UPGRADES][3], g_szUpgrade_Name[MAX_UPGRADES][64];

public plugin_init(){
	register_plugin("RPGx", "2.1", "roflmao456");
	register_cvar("rpgx_version", "2.1", FCVAR_SPONLY|FCVAR_SERVER);
	#if _SQL
		g_pSQLHost = register_cvar("rpgx_sql_host", "", FCVAR_PROTECTED);
		g_pSQLUser = register_cvar("rpgx_sql_user", "", FCVAR_PROTECTED);
		g_pSQLPass = register_cvar("rpgx_sql_pass", "", FCVAR_PROTECTED);
		g_pSQLDB = register_cvar("rpgx_sql_db", "", FCVAR_PROTECTED);
		g_pSQLTable = register_cvar("rpgx_sql_table", "RPGx", FCVAR_PROTECTED);
		
		new szConfigDir[64];
		get_configsdir(szConfigDir, 63);
		server_cmd("exec %s/rpgx/sql.cfg", szConfigDir);
		server_exec();
		
		get_pcvar_string(g_pSQLHost, g_szSQLHost, 63);
		get_pcvar_string(g_pSQLUser, g_szSQLUser, 63);
		get_pcvar_string(g_pSQLPass, g_szSQLPass, 63);
		get_pcvar_string(g_pSQLDB, g_szSQLDB, 63);
		get_pcvar_string(g_pSQLTable, g_szSQLTable, 63);
		
		g_hSQLTuple = SQL_MakeDbTuple(g_szSQLHost, g_szSQLUser, g_szSQLPass, g_szSQLDB);
		
		new iError, szError[256];
		new Handle:hSQLConnection = SQL_Connect(g_hSQLTuple, iError, szError, 255);
		
		if(hSQLConnection != Empty_Handle){
			SQL_QueryAndIgnore(hSQLConnection,
				"CREATE TABLE IF NOT EXISTS `%s` (\
					authid VARCHAR(64) NOT NULL PRIMARY KEY, \
					level INT NOT NULL DEFAULT 0, \
					experience INT NOT NULL DEFAULT 0, \
					credits INT NOT NULL DEFAULT 0, \
					upgrades VARCHAR(128) NOT NULL \
				) ENGINE=MyISAM;", g_szSQLTable);
			SQL_FreeHandle(hSQLConnection);
			}
	#endif
	#if _VAULT
		g_hVault = nvault_open("RPGx");
	#endif
	
	g_pXPNotice = register_cvar("rpgx_xp_notice", "1");
	g_pXPMax = register_cvar("rpgx_xp_max", "50000");
	g_pXPStart = register_cvar("rpgx_xp_start", "250");
	g_pXPInc = register_cvar("rpgx_xp_inc", "75");
	g_pXPKill = register_cvar("rpgx_xp_kill", "15");
	g_pXPHeadshot = register_cvar("rpgx_xp_headshot", "50");
	g_pXPDamage = register_cvar("rpgx_xp_damage", "1.0");
	g_pXPKnifeDmg = register_cvar("rpgx_xp_knifedmg", "8.0");
	g_pXPTeamWin = register_cvar("rpgx_xp_teamwin", "0.15");
	g_pXPBombPlant = register_cvar("rpgx_xp_bombplanted", "0.15");
	g_pXPBombDefuse = register_cvar("rpgx_xp_bombdefused", "0.30");
	g_pXPBombExplode = register_cvar("rpgx_xp_bombexploded", "0.20");
	
	g_pCreditsInc = register_cvar("rpgx_credits_inc", "5");
	g_pCreditsStart = register_cvar("rpgx_credits_start", "5");
	g_pCreditsSellPct = register_cvar("rpgx_credits_sellpercent", "0.75");
	
	g_fwPluginReady = CreateMultiForward("RPGx_OnPluginReady", ET_IGNORE);
	g_fwPluginAuth = CreateMultiForward("RPGx_OnPlayerAuth", ET_IGNORE, FP_CELL);
	g_fwPluginUpgradePurchase = CreateMultiForward("RPGx_OnUpgradePurchase", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL);
	g_fwPluginUpgradeSell = CreateMultiForward("RPGx_OnUpgradeSell", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL);
	g_fwPlayerSpawn = CreateMultiForward("RPGx_OnPlayerSpawn", ET_IGNORE, FP_CELL);
	g_fwPlayerLevelUp = CreateMultiForward("RPGx_OnPlayerLevel", ET_IGNORE, FP_CELL, FP_CELL);
	g_fwPlayerDeath = CreateMultiForward("RPGx_OnPlayerDeath", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL);
	g_fwPlayerHurt = CreateMultiForward("RPGx_OnPlayerHurt", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL, FP_CELL);
	
	register_clcmd("say rpgmenu", "RPGx_ShowMainMenu");
	register_clcmd("say /rpgmenu", "RPGx_ShowMainMenu");
	
	register_message(get_user_msgid("TextMsg"), "OnEvent_TextMsg");
	
	register_dictionary("rpgx.txt");
	
	RegisterHam(Ham_Spawn, "player", "OnPlayerEvent_Spawn", 1);
	}

public plugin_cfg(){
	new szConfigDir[64];
	get_configsdir(szConfigDir, 63);
	server_cmd("exec %s/rpgx/rpgx.cfg", szConfigDir);
	
	ExecuteForward(g_fwPluginReady, g_fwLastResult);
	}

public plugin_natives(){
	register_native("RPGx_MakeUpgrade", "Native_MakeUpgrade", 1);	
	register_native("RPGx_GetUpgradeLevel", "Native_GetUpgradeLevel", 1);
	register_native("RPGx_GetUpgradeMaxLevel", "Native_GetUpgradeMaxLevel", 1);
	register_native("RPGx_Freeze", "Native_Freeze", 1);
	register_native("RPGx_IsFrozen", "Native_IsFrozen", 1);
	register_native("RPGx_GetXP", "Native_GetXP", 1);
	register_native("RPGx_GetLevel", "Native_GetLevel", 1);
	register_native("RPGx_GetCredits", "Native_GetCredits", 1);
	register_native("RPGx_SetSpawnHealth", "Native_SetSpawnHealth", 1);
	register_native("RPGx_GetSpawnHealth", "Native_GetSpawnHealth", 1);
	}

public plugin_precache(){
	precache_sound("rpgx/levelup.wav");
	precache_sound("rpgx/reset_stats.wav");
	precache_sound("rpgx/upgrade_purchase.wav");
	precache_sound("rpgx/upgrade_sell.wav");
	precache_sound("rpgx/upgrade_error.wav");
	precache_sound("rpgx/menu_select.wav");
	precache_sound("rpgx/menu_exit.wav");
	}

#if SAVABLE
public plugin_end(){
	#if _VAULT
	nvault_close(g_hVault);
	#endif
	#if _SQL
	SQL_FreeHandle(g_hSQLTuple);
	#endif
	}

public client_disconnect(id)
	RPGx_Save(id);

RPGx_Save(id){
	new szAuthId[64], data[129], upgrade[5];
	get_user_authid(id, szAuthId, 63);
	
	for(new i;i<g_iUpgrades;i++){
		formatex(upgrade, 4, "%i ", g_iUpgrade_Level[id][i]);
		add(data, 128, upgrade);
		}
	
	#if _VAULT
	new key[72], stats[34];
	formatex(key, 71, "%s-stats", szAuthId);
	formatex(stats, 33, "%i %i %i", g_iLevel[id], g_iXP[id], g_iCredits[id]);
	nvault_set(g_hVault, key, stats);
	nvault_set(g_hVault, szAuthId, data);
	#endif
	#if _SQL
	new szQuery[129];
	formatex(szQuery, 128, "REPLACE INTO `%s` VALUES ('%s', %d, %d, %d, '%s');", g_szSQLTable, szAuthId, g_iLevel[id], g_iXP[id], g_iCredits[id], data);
	SQL_ThreadQuery(g_hSQLTuple, "RPGx_HandleSQL", szQuery);
	#endif
	}

RPGx_Load(id){
	new szAuthId[64], data[129];
	get_user_authid(id, szAuthId, 63);
	
	#if _VAULT
	new key[72], stats[34], stat[3][12];
	formatex(key, 71, "%s-stats", szAuthId);
	
	nvault_get(g_hVault, key, stats, 33);
	
	parse(stats, stat[0], 11, stat[1], 11, stat[2], 11);
	
	g_iLevel[id] = str_to_num(stat[0]);
	g_iXP[id] = str_to_num(stat[1]);
	g_iCredits[id] = str_to_num(stat[2]);
	
	if(!g_iCredits[id])
		g_iCredits[id] = get_pcvar_num(g_pCreditsStart);
	
	nvault_get(g_hVault, szAuthId, data, 128);
	LoadUserUpgradeStats(id, data);
	
	ExecuteForward(g_fwPluginAuth, g_fwLastResult, id);
	#else
		#if _SQL
		new szQuery[129];
		num_to_str(id, data, 2);
		formatex(szQuery, 128, "SELECT * FROM `%s` WHERE authid = '%s';", g_szSQLTable, szAuthId);
		SQL_ThreadQuery(g_hSQLTuple, "RPGx_HandleSQL", szQuery, data, 3);
		#endif
	#endif
	}

#if _SQL
public RPGx_HandleSQL(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime){
	if(SQL_NumResults(query)){
		new id = str_to_num(data);
		g_iLevel[id] = SQL_ReadResult(query, 1);
		g_iXP[id] = SQL_ReadResult(query, 2);
		g_iCredits[id] = SQL_ReadResult(query, 3);
		
		new stats[129];
		SQL_ReadResult(query, 4, stats, 128);
		
		LoadUserUpgradeStats(id, stats);
		
		ExecuteForward(g_fwPluginAuth, g_fwLastResult, id);
		}
	}
#endif

LoadUserUpgradeStats(id, data[]){
	if(equal(data, ""))
		return;
	new upgradelevel[6], remover[6], i;
	parse(data, upgradelevel, 5);
	formatex(remover, 5, upgradelevel);
	while(replace(data, 128, remover, "")){
		g_iUpgrade_Level[id][i++] = str_to_num(upgradelevel);
		parse(data, upgradelevel, 5);
		formatex(remover, 5, upgradelevel);
		}
	g_iUpgrade_Level[id][i] = str_to_num(upgradelevel);
	for(new x;x<g_iUpgrades;x++){
		if(g_iUpgrade_Level[id][x] > g_iUpgrade_Info[x][0])
			g_iUpgrade_Level[id][x] = g_iUpgrade_Info[x][0];
		}
	}
#endif

public client_putinserver(id){
	g_iCredits[id] = get_pcvar_num(g_pCreditsStart);
	g_iLevel[id] = 0;
	g_iXP[id] = 0;
	g_iSpawnHealth[id] = 100;
	arrayset(g_iUpgrade_Level[id], 0, g_iUpgrades);
	#if SAVABLE
	RPGx_Load(id);
	#else
	ExecuteForward(g_fwPluginAuth, g_fwLastResult, id);
	#endif
	}

public OnPlayerEvent_Spawn(id){
	if(is_user_alive(id)){
		client_print(id, print_chat, "%L", id, "rpgx_running");
		set_user_health(id, g_iSpawnHealth[id]);
		ExecuteForward(g_fwPlayerSpawn, g_fwLastResult, id);
		}
	}

public OnEvent_TextMsg(){
	new szTextMsg[16];
	get_msg_arg_string(2, szTextMsg, 15);
	
	new players[32], num, player;
	
	if(equal(szTextMsg, "#Terrorists_Win"))
		get_players(players, num, "e", "TERRORIST");
	if(equal(szTextMsg, "#CTs_Win"))
		get_players(players, num, "e", "CT");
	
	for(new i;i<num;i++){
		player = players[i];
		g_iXP[player] += floatround(required_xp(player) * get_pcvar_float(g_pXPTeamWin));
		RPGx_CheckXP(player);
		}
	}

public client_damage(attacker, victim, damage, wpnindex, hitplace, TA){
	if(!TA && attacker != victim){
		g_iXP[attacker] += floatround(damage * get_pcvar_float(wpnindex == CSW_KNIFE?g_pXPKnifeDmg:g_pXPDamage));
		RPGx_CheckXP(attacker);
		}
	ExecuteForward(g_fwPlayerHurt, g_fwLastResult, victim, attacker, damage, wpnindex);
	}

public client_death(killer, victim, wpnindex, hitplace, TK){
	new headshot = hitplace==HIT_HEAD?1:0;
	if(!TK && killer != victim){
		g_iXP[killer] += get_pcvar_num(g_pXPKill) + headshot?get_pcvar_num(g_pXPHeadshot):0;
		RPGx_CheckXP(killer);
		}
	ExecuteForward(g_fwPlayerDeath, g_fwLastResult, victim, killer, headshot);
	}

public bomb_defused(defuser){
	g_iXP[defuser] += floatround(required_xp(defuser) * get_pcvar_float(g_pXPBombDefuse));
	RPGx_CheckXP(defuser);
	}

public bomb_planted(planter){
	g_iXP[planter] += floatround(required_xp(planter) * get_pcvar_float(g_pXPBombPlant));
	RPGx_CheckXP(planter);
	}

public bomb_explode(planter, defuser){
	new players[32], num, player;
	get_players(players, num, "e", "TERRORIST");
	for(new i;i<num;i++){
		player = players[i];
		g_iXP[player] += floatround(required_xp(player) * get_pcvar_float(g_pXPBombExplode));
		RPGx_CheckXP(player);
		}
	g_iXP[planter] += floatround(required_xp(planter) * get_pcvar_float(g_pXPBombPlant));
	g_iXP[defuser]++;
	RPGx_CheckXP(planter);
	RPGx_CheckXP(defuser);
	}

RPGx_CheckXP(id){
	new XP = g_iXP[id];
	if(XP >= required_xp(id)){
		new MaxXP = get_pcvar_num(g_pXPMax);
		if(MaxXP > 0 && XP >= MaxXP)
			return;
		g_iXP[id] -= required_xp(id);
		g_iLevel[id]++;
		g_iCredits[id] += get_pcvar_num(g_pCreditsInc);
		
		if(get_pcvar_num(g_pXPNotice)){
			new szName[32];
			get_user_name(id, szName, 31);
			client_print(0, print_chat, "%L", LANG_PLAYER, "rpgx_stats_levelup", szName, g_iLevel[id]);
			}
		
		client_print(id, print_chat, "%L", id, "rpgx_notice_newcredits", g_iCredits[id]);
		
		PlaySound(id, "levelup");
		ExecuteForward(g_fwPlayerLevelUp, g_fwLastResult, id, g_iLevel[id]);
		}
	}

public Native_MakeUpgrade(const name[], maxlevel, cost, icost){
	if(g_iUpgrades < MAX_UPGRADES){
		param_convert(1);
		formatex(g_szUpgrade_Name[g_iUpgrades], 63, name);
		g_iUpgrade_Info[g_iUpgrades][0] = maxlevel;
		g_iUpgrade_Info[g_iUpgrades][1] = cost;
		g_iUpgrade_Info[g_iUpgrades][2] = icost;
		g_iUpgrades++;
		return g_iUpgrades-1;
		}
	return -1;
	}

public Native_GetUpgradeLevel(player, upgrade)
	return g_iUpgrade_Level[player][upgrade];

public Native_GetUpgradeMaxLevel(upgrade)
	return g_iUpgrade_Info[upgrade][0];

public Native_Freeze(player, bool:freeze){
	g_bIsFrozen[player] = freeze;
	set_user_maxspeed(player, freeze?10.0:240.0);
	set_user_rendering(player, freeze?kRenderFxGlowShell:kRenderFxNone, 0, 0, 255, kRenderNormal, 25);
	}

public Native_IsFrozen(player)
	return g_bIsFrozen[player];

public Native_GetXP(player)
	return g_iXP[player];

public Native_GetLevel(player)
	return g_iLevel[player];

public Native_GetCredits(player)
	return g_iCredits[player];

public Native_SetSpawnHealth(player, health)
	g_iSpawnHealth[player] = health;

public Native_GetSpawnHealth(player)
	return g_iSpawnHealth[player];

public RPGx_ShowMainMenu(id){
	new menu = menu_create("Main Menu", "HandleMainMenu");
	
	menu_additem(menu, "Purchase Upgrades");
	menu_additem(menu, "Sell Upgrades");
	menu_additem(menu, "View Stats");
	menu_additem(menu, "About RPGx");
	
	menu_setprop(menu, MPROP_EXIT, MEXIT_NORMAL);
	
	menu_display(id, menu);
	return PLUGIN_HANDLED;
	}

public HandleMainMenu(id, menu, item){
	PlaySound(id, item != MENU_EXIT?"menu_select":"menu_exit");
	switch(item){
		case 0:PurchaseMenu(id);
		case 1:SellMenu(id);
		case 2:StatsMenu(id);
		case 3:AboutRPGx(id);
		}
	menu_destroy(menu);
	}

PurchaseMenu(id){
	new szTempStr[86], szTitle[64], iLevel;
	formatex(szTitle, 63, "Upgrade Shop - Purchase [Cr: %i]", g_iCredits[id]);
	new menu = menu_create(szTitle, "HandlePurchaseMenu");
	
	for(new i;i<g_iUpgrades;i++){
		iLevel = g_iUpgrade_Level[id][i];
		formatex(szTempStr, 85, "%s Level %i [Cost: %i]", g_szUpgrade_Name[i], iLevel + 1, g_iUpgrade_Info[i][1] + (iLevel * g_iUpgrade_Info[i][2]));
		menu_additem(menu, szTempStr);
		}
	
	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
	
	if(g_iUpgrades)
		menu_display(id, menu);
		else {
		menu_destroy(menu);
		client_print(id, print_chat, "%L", id, "rpgx_error_noupgrades");
		}
	}

public HandlePurchaseMenu(id, menu, item){
	if(item > MENU_EXIT){
		new iCost = g_iUpgrade_Info[item][1] + (g_iUpgrade_Level[id][item] * g_iUpgrade_Info[item][2]);
		if(g_iCredits[id] >= iCost){
			if(g_iUpgrade_Level[id][item] < g_iUpgrade_Info[item][0]){
				g_iCredits[id] -= iCost;
				ExecuteForward(g_fwPluginUpgradePurchase, g_fwLastResult, id, item, ++g_iUpgrade_Level[id][item]);
				client_print(id, print_chat, "%L", id, "rpgx_shop_buy_success", g_szUpgrade_Name[item], g_iUpgrade_Level[id][item]);
				PurchaseMenu(id);
				PlaySound(id, "upgrade_purchase");
				} else {
				client_print(id, print_chat, "%L", id, "rpgx_shop_buy_error_maxlevel");
				PurchaseMenu(id);
				PlaySound(id, "upgrade_error");
				}
			} else {
			client_print(id, print_chat, "%L", id, "rpgx_shop_buy_error_insufficient");
			PurchaseMenu(id);
			PlaySound(id, "upgrade_error");
			}
		} else
		PlaySound(id, item != MENU_EXIT?"menu_select":"menu_exit");
	menu_destroy(menu);
	}

SellMenu(id){
	new szTempStr[86], szTitle[64], iLevel;
	formatex(szTitle, 63, "Upgrade Shop - Sell [Cr: %i]", g_iCredits[id]);
	new menu = menu_create(szTitle, "HandleSellMenu");
	
	for(new i;i<g_iUpgrades;i++){
		iLevel = g_iUpgrade_Level[id][i];
		formatex(szTempStr, 85, "%s Level %i [Credit: %i]", g_szUpgrade_Name[i], iLevel, floatround((iLevel * g_iUpgrade_Info[i][2]) * get_pcvar_float(g_pCreditsSellPct)));
		menu_additem(menu, szTempStr);
		}
	
	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
	
	if(g_iUpgrades)
		menu_display(id, menu);
		else {
		menu_destroy(menu);
		client_print(id, print_chat, "%L", id, "rpgx_error_noupgrades");
		}
	}

public HandleSellMenu(id, menu, item){
	if(item > MENU_EXIT){
		if(g_iUpgrade_Level[id][item] > 0){
			g_iCredits[id] += floatround((g_iUpgrade_Level[id][item] * g_iUpgrade_Info[item][2]) * get_pcvar_float(g_pCreditsSellPct));
			ExecuteForward(g_fwPluginUpgradeSell, g_fwLastResult, id, item, --g_iUpgrade_Level[id][item]);
			client_print(id, print_chat, "%L", id, "rpgx_shop_sell_success", g_szUpgrade_Name[item], g_iUpgrade_Level[id][item]+1);
			SellMenu(id);
			PlaySound(id, "upgrade_sell");
			} else {
			client_print(id, print_chat, "%L", id, "rpgx_shop_error_notpurchased");
			SellMenu(id);
			PlaySound(id, "upgrade_error");
			}
		} else
		PlaySound(id, item != MENU_EXIT?"menu_select":"menu_exit");
	menu_destroy(menu);
	}

StatsMenu(id){
	new szTempStr[32];
	new menu = menu_create("Current Stats", "HandleStatsMenu");
	menu_additem(menu, "Reset Stats");
	
	menu_addblank(menu);
	
	formatex(szTempStr, 31, "Level: %i", g_iLevel[id]);
	menu_addtext(menu, szTempStr);
	
	formatex(szTempStr, 31, "Credits: %i", g_iCredits[id]);
	menu_addtext(menu, szTempStr);
	
	formatex(szTempStr, 31, "XP: %i/%i", g_iXP[id], required_xp(id));
	menu_addtext(menu, szTempStr);
	
	menu_setprop(menu, MPROP_EXIT, MEXIT_NORMAL);
	
	menu_display(id, menu);
	}

public HandleStatsMenu(id, menu, item){
	PlaySound(id, item != MENU_EXIT?"menu_select":"menu_exit");
	if(!item){
		new menu2 = menu_create("Reset Stats?", "HandleConfirmReset");
		
		menu_additem(menu2, "Yes");
		menu_additem(menu2, "No");
		
		menu_display(id, menu2);
		}
	menu_destroy(menu);
	}

public HandleConfirmReset(id, menu, item){
	if(!item){
		g_iCredits[id] = get_pcvar_num(g_pCreditsStart);
		g_iLevel[id] = 0;
		g_iXP[id] = 0;
		g_iSpawnHealth[id] = 100;
		arrayset(g_iUpgrade_Level[id], 0, g_iUpgrades);
		client_print(id, print_chat, "%L", id, "rpgx_stats_reset");
		PlaySound(id, "reset_stats");
		}
	if(item == 1)
		StatsMenu(id);
	menu_destroy(menu);
	}

AboutRPGx(id){
	new menu = menu_create("About RPGx", "AboutHandler");
	
	menu_additem(menu, "Back to Main Menu");
	
	menu_addblank(menu);
	
	menu_addtext(menu, "Author: roflmao456");
	menu_addtext(menu, "Website: update.meetcweb.com");
	
	menu_addblank(menu);
	
	menu_addtext(menu, "Inspired by sumguy14's RPGx (SourceMod).");
	
	menu_display(id, menu);
	}

public AboutHandler(id, menu, item){
	if(!item)
		RPGx_ShowMainMenu(id);
	menu_destroy(menu);
	}